package cj.web.tb.controllers;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;

import cj.web.admin.utils.DateUtils;
import cj.web.tb.dao.GameDAO;
import cj.web.tb.dao.ReportsDAO;

@Path("reports")
public class ReportsController {

	@Autowired
	private ReportsDAO reportsDao;
	@Autowired
	private GameDAO gameDao;
	
	@Get("showSmtj")
	public String showSmtjInfo(Model model){
		List<Map> gamelis =  gameDao.queryAllForEndDate();
		model.add("gamelis", gamelis);
		return "/views/report/smtjInfoList.vm";
	}
	
	@Post("getList")
    public String getList(@Param("gameId") Integer gameId,@Param("startAt") String startAt,@Param("endAt") String endAt,
    		@Param("page") Integer page,@Param("rows") Integer rows) throws ParseException{
		
		//当前页  
		int start = (page-1)*rows;
		int length = rows;
		
		JSONObject jo = new JSONObject();
		
		List<Map> arr = reportsDao.queryReportsSmtj(gameId, startAt, endAt, start, length);
		
		for(Map obj:arr){
			obj.put("updateAt",DateUtils.formatDateStr(obj.get("updateAt").toString(), DateUtils.DATE_FULL_STR));
		}
		
		int size = reportsDao.queryReportsSmtjSize(gameId, startAt, endAt);
		
		jo.put("rows", arr);
		jo.put("total", size);
		
		return "@" + jo.toString();
	}
	
	@Get("showSptj")
	public String showSptjInfo(Model model){
		List<Map> gamelis =  gameDao.queryAllForEndDate();
		model.add("gamelis", gamelis);
		return "/views/report/sptjInfoList.vm";
	}
	
	@Post("getSptjList")
    public String getSptjList(@Param("gameId") Integer gameId,@Param("startAt") String startAt,@Param("endAt") String endAt) throws ParseException{
		
		//当前页  
		int start = 0;
		int length = 99999;
		
		JSONObject jo = new JSONObject();
		
		List<Map> arr = reportsDao.queryReportsSptj(gameId, startAt, endAt, start, length);
		
//		int size = reportsDao.queryReportsSptjSize(gameId, startAt, endAt);
		
		jo.put("rows", arr);
//		jo.put("total", size);
		
		return "@" + jo.toString();
	}
}
